package com.qfjy.project.weixin.api.message;

import com.qfjy.project.weixin.api.accessToken.AccessTokenThread;
import com.qfjy.project.weixin.api.message.bean.CustomTextBean;
import com.qfjy.project.weixin.api.message.bean.text.CustomTextTypeBean;
import com.qfjy.project.weixin.util.WeixinUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class CustomMessageUtil {

    private static String WEIXIN_MESSAGE_CUSTOM_SEND="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";


    public void sendMessageText(String openid,String content){
        CustomTextBean customTextBean = new CustomTextBean();
        customTextBean.setMsgtype("text");
        customTextBean.setTouser(openid);
        CustomTextTypeBean customTextTypeBean = new CustomTextTypeBean();
        customTextTypeBean.setContent(content);
        customTextBean.setText(customTextTypeBean);

        JSONObject jsonObject = JSONObject.fromObject(customTextBean);
        log.info("发送微信请求参数:{}",jsonObject.toString());
        String url = WEIXIN_MESSAGE_CUSTOM_SEND.replace("ACCESS_TOKEN", AccessTokenThread.WEIXIN_TOKEN_VALUE);
        WeixinUtil.httpRequest(url,"POST",jsonObject.toString());

    }
}
